document.getElementById("addLevel").onclick=function(){
	window.open ("addMemLevel.html?type=POST", "_blank", "height=400, width=600, top=160, left=200, toolbar=no, menubar=no, scrollbars=yes, resizable=no, location=no, status=no");
}
document.getElementById("addFree").onclick=function(){
	window.open ("add_charge_level.html?type=POST", "_blank", "height=400, width=600, top=160, left=200, toolbar=no, menubar=no, scrollbars=yes, resizable=no, location=no, status=no");
}
document.getElementById("addSiteLevel").onclick=function(){
	window.open ("add_site_level.html?type=POST", "_blank", "height=400, width=600, top=160, left=200, toolbar=no, menubar=no, scrollbars=yes, resizable=no, location=no, status=no");
}
document.getElementById("addConsumptionLevel").onclick=function(){
	window.open ("add_consumption_level.html?type=POST", "_blank", "height=400, width=600, top=160, left=200, toolbar=no, menubar=no, scrollbars=yes, resizable=no, location=no, status=no");
}
document.getElementById("addConsumptionFree").onclick=function(){
	window.open ("oil_free.html?type=POST", "_blank", "height=500, width=800, top=160, left=200, toolbar=no, menubar=no, scrollbars=yes, resizable=no, location=no, status=no");
}
function getList(){
	$.ajax({
		"url":"/mem_level/",
		"error":errorAjax,
		"complete":stop_load_pic,
		"beforeSend":start_load_pic,
		"dataType":"jsonp",
		"success":function(data){
			if(responseCheck(data)){
				/*返现参数设置*/
				var t=data.content.mem_level
				for(var i=0;i<t.length;i++){

				var tab= document.getElementById("tab1")
				tr=document.createElement("tr")

				var td=document.createElement("td")
				td.textContent=t[i].level +"星级会员"
				tr.appendChild(td)
				
				var td=document.createElement("td")
				td.textContent=t[i].value
				tr.appendChild(td)
				
				var td=document.createElement("td")
				td.textContent=t[i].free
				tr.appendChild(td)
				
				var td=document.createElement("td")
				var btn=document.createElement("td")
				btn.textContent="修改"
				btn.className="btn btn-primary btn-xs"
				btn.setAttribute("data",JSON.stringify(t[i]))
				btn.onclick=function(){
					var data=this.getAttribute("data")
					window.open ("addMemLevel.html?type=PUT&data="+data, "_blank", "height=400, width=600, top=160, left=200, toolbar=no, menubar=no, scrollbars=yes, resizable=no, location=no, status=no");
				}
				td.appendChild(btn)
				tr.appendChild(td)
				tab.appendChild(tr)
				}
				for(var i=0;i<data.content.charge_level.length;i++){
				var tab= document.getElementById("tab2")
				tr=document.createElement("tr")

				var td=document.createElement("td")
				td.textContent=data.content.charge_level[i].cash
				tr.appendChild(td)
				
				var td=document.createElement("td")
				td.textContent=data.content.charge_level[i].give
				tr.appendChild(td)
				
				var td=document.createElement("td")
				var btn=document.createElement("td")
				btn.className="btn btn-primary btn-xs"
				btn.textContent="修改"
				btn.setAttribute("data",JSON.stringify(data.content.charge_level[i]))
				btn.onclick=function(){
					var data=this.getAttribute("data")
					window.open ("add_charge_level.html?type=PUT&data="+data, "_blank", "height=400, width=600, top=160, left=200, toolbar=no, menubar=no, scrollbars=yes, resizable=no, location=no, status=no");
				}
				td.appendChild(btn)
				tr.appendChild(td)
				tab.appendChild(tr)

				}

				for(var i=0;i<data.content.site_level.length;i++){
				var tab= document.getElementById("tab3")
				tr=document.createElement("tr")

				var td=document.createElement("td")
				td.textContent=data.content.site_level[i].site_level_id +"级加油站"
				tr.appendChild(td)
				
				var td=document.createElement("td")
				td.textContent=data.content.site_level[i].free
				tr.appendChild(td)
				
				var td=document.createElement("td")
				var btn=document.createElement("td")
				btn.className="btn btn-primary btn-xs"
				btn.textContent="修改"
				btn.setAttribute("data",JSON.stringify(data.content.site_level[i]))
				btn.onclick=function(){
					var data=this.getAttribute("data")
					window.open ("add_site_level.html?type=PUT&data="+data, "_blank", "height=400, width=600, top=160, left=200, toolbar=no, menubar=no, scrollbars=yes, resizable=no, location=no, status=no");
				}
				td.appendChild(btn)
				tr.appendChild(td)
				tab.appendChild(tr)

				}
				var tab= document.getElementById("tab4")
				for(var i=0;i<data.content.consumption_level.length;i++){
				tr=document.createElement("tr")

				var td=document.createElement("td")
				td.textContent=data.content.consumption_level[i].level
				tr.appendChild(td)
				
				var td=document.createElement("td")
				td.textContent=data.content.consumption_level[i].free
				tr.appendChild(td)
				
				var td=document.createElement("td")
				var btn=document.createElement("td")
				btn.className="btn btn-primary btn-xs"
				btn.textContent="修改"
				btn.setAttribute("data",JSON.stringify(data.content.consumption_level[i]))
				btn.onclick=function(){
					var data=this.getAttribute("data")
					window.open ("add_consumption_level.html?type=PUT&data="+data, "_blank", "height=400, width=600, top=160, left=200, toolbar=no, menubar=no, scrollbars=yes, resizable=no, location=no, status=no");
				}
				td.appendChild(btn)
				tr.appendChild(td)
				tab.appendChild(tr)

				}
				//下面是燃油优惠设置
				var tab= document.getElementById("tab5")
				for(var i=0;i<data.content.oil_free.length;i++){
					var tr=document.createElement("tr")
					var oil=data.content.oil_free[i].oil
					if(oil==="92" || oil==="95"){
						var member_free=data.content.oil_free[i].member_free+"%"
						var free=data.content.oil_free[i].free+"%"
					}
					else{
						var member_free="￥"+data.content.oil_free[i].member_free+"/L"
						var free="￥"+data.content.oil_free[i].free+"/L"
					}
					var td=document.createElement("td")
					td.textContent=oil+" #"
					tr.appendChild(td)
					
					var td=document.createElement("td")
					td.textContent=data.content.oil_free[i].first_consumption +" - " +data.content.oil_free[i].last_consumption
					tr.appendChild(td)
					
					var td=document.createElement("td")
					td.textContent=free
					tr.appendChild(td)
					
					var td=document.createElement("td")
					td.textContent=member_free
					tr.appendChild(td)
					
					var td=document.createElement("td")
					var btn=document.createElement("button")
					btn.className="btn btn-xs btn-primary"
					btn.setAttribute("data",JSON.stringify(data.content.oil_free[i]))
					btn.textContent="修改"
					btn.onclick=function(){
						var data=this.getAttribute("data")
						window.open ("oil_free.html?type=PUT&data="+data, "_blank", "height=500, width=800, top=160, left=200, toolbar=no, menubar=no, scrollbars=yes, resizable=no, location=no, status=no");
						
					}
					td.appendChild(btn)
					tr.appendChild(td)

					var btn=document.createElement("button")
					btn.style.marginLeft="5px"
					btn.className="btn btn-xs btn-danger"
					btn.setAttribute("_id",data.content.oil_free[i].id)
					btn.textContent="删除"
					btn.onclick=function(){
						var _id=this.getAttribute("_id")
						var tr=this.parentNode.parentNode
						var t=confirm("确定要删除吗？")
						if (t){
							$.ajax({
								"url":"/oil_free/",
								"error":errorAjax,
								"sendBefore":start_load_pic,
								"complete":stop_load_pic,
								"type":"DELETE",
								"data":{"id":_id},
								"success":function(data){
									if(responseCheck(data)){
										$(tr).remove()
									}
								}
							})
						}
						
					}
					td.appendChild(btn)
					tr.appendChild(td)
					tab.appendChild(tr)
					
					
				}
			}
		}
	})
}
getList()
